import * as step from '@flow-step/step-toolkit'
import process from 'process'
import {getParams} from './params'
import {execute} from './execute'

export const IS_LINUX = process.platform === 'linux'
export const IS_X64 = process.arch === 'x64'

async function runStep(): Promise<void> {
    if (!IS_LINUX || !IS_X64) {
        // outputs2template golang binary support linux/amd64 only now
        throw new Error('KubectlSae only supports Linux/amd64 systems now')
    }

    const params = getParams()
    step.infoV1(`PIPELINE_ID=${params.pipelineID}`)
    step.infoV1(`PIPELINE_NAME=${params.pipelineName}`)
    step.infoV1(`BUILD_NUMBER=${params.buildNumber}`)
    step.infoV1(`WORK_SPACE=${params.workSpace}`)
    step.infoV1(`PROJECT_DIR=${params.projectDir}`)
    step.infoV1(`BUILD_JOB_ID=${params.buildJobID}`)

    await execute(params)
}

runStep()
    .then(function() {
        step.success('run step successfully!')
    })
    .catch(function(err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
